import { configureStore } from "@reduxjs/toolkit";
import {
  type TypedUseSelectorHook,
  useSelector,
  useDispatch,
} from "react-redux";

import authReducer from "./modules/auth";
import coffeeReducer from "./modules/coffee";
import coffeeSelectionReducer from "./modules/coffeeSelection";
import coffeeOrderReducer from "./modules/coffeeOrder";

const store = configureStore({
  reducer: {
    auth: authReducer,
    coffee: coffeeReducer,
    coffeeSelection: coffeeSelectionReducer,
    coffeeOrder: coffeeOrderReducer,
  },
});

// 封装useSelector  不然每次使用都要导入StateType类型
export type StateType = ReturnType<typeof store.getState>;
type DispatchType = typeof store.dispatch;

export const useAppSelector: TypedUseSelectorHook<StateType> = useSelector;
export const useAppDispatch: () => DispatchType = useDispatch;

export default store;
